-- shanjaq: Start Life Support mod.
local FairTemp = 288
local ls_habitat = 0
local ls_air = 0
local ls_tmp = 0
local ls_shd = 0

local function lifesupport_HUDPaint()
	if GetConVarString('cl_hudversion') == "" then
		local ply = LocalPlayer()
		
		if !ply:Alive() then return end
		
		local ply = LocalPlayer()
		local guage_thickness = ScrH() / 40
		local guage_length = ScrW() / 10
		
		local box_width = ScrW() / 28
		local box_height = ScrH() / 28
		
		if (( ply:WaterLevel() > 2 ) or (ls_habitat == 1)) then
			local lungs_max = 100
			local air_lungs = 0
			local reserve_max = 1900
			local air_reserve = 0
			
			if ( ls_air > lungs_max ) then
				air_lungs = lungs_max
				air_reserve = ( ls_air - lungs_max )
			else
				air_lungs = ls_air
				air_reserve = 0
			end
			--frame
			draw.RoundedBox( 0, ((ScrW() / 2) - (guage_length / 2)), ScrH() - guage_thickness, guage_length, guage_thickness, Color(255,255,255,225) )
			--reserve
			draw.RoundedBox( 0, ((ScrW() / 2) - (guage_length / 2)), ScrH() - guage_thickness, (guage_length * (air_reserve / reserve_max)), (guage_thickness / 3), Color(80,200,80,225) )
			--lungs
			draw.RoundedBox( 0, ((ScrW() / 2) - (guage_length / 2)), ScrH() - ((guage_thickness / 3) * 2), (guage_length * (air_lungs / lungs_max)), ((guage_thickness / 3) * 2), Color(80,80,200,225) )
			
		end
		if (ls_tmp > 0) then
			if (((ls_tmp or 0) < FairTemp) or ((ls_tmp or 0) > FairTemp)) then
				local shd_max = 2000
				local shd_reserve = 0
			
				if (ls_tmp < FairTemp) then
					if (ls_tmp >= 0) then
						TempColor = Color(0,0,255,(255 - ((ls_tmp / FairTemp) * 255)))
					else
						TempColor = Color(0,0,255,255)
					end
				elseif (ls_tmp > FairTemp) then
					if (ls_tmp < (FairTemp * 2)) then
						TempColor = Color(255,0,0,(((ls_tmp - FairTemp) / FairTemp) * 255))
					else
						TempColor = Color(255,0,0,255)
					end
				else
					TempColor = Color(0,255,0,255)
				end
				--frame
				draw.RoundedBox( 0, ((ScrW() / 2) + (guage_length / 2)), ScrH() - box_height, box_width, box_height, Color(0,255,0,225) )
				--external temp
				draw.RoundedBox( 0, ((ScrW() / 2) + (guage_length / 2)), ScrH() - box_height, box_width, box_height, TempColor )
				--reserve
				if (ls_shd > 0) then
					draw.RoundedBox( 0, (((ScrW() / 2) + (guage_length / 2)) + (box_width / 5.5)), ScrH() - (box_height / 1.3), (box_width / 1.6), (box_height / 1.5), Color(255,255,255,((ls_shd / shd_max) * 255)) )
				end
				--body
				if (ls_shd > 0) then
					draw.RoundedBox( 0, (((ScrW() / 2) + (guage_length / 2)) + (box_width / 4)), ScrH() - (box_height / 1.5), (box_width / 2), (box_height / 2), Color(0,255,0,225) )
				end
				draw.WordBox( 8, (((ScrW() / 2) + (guage_length / 2)) + box_width), ScrH() - box_height, string.format("Temperature: %d",ls_tmp), "Default", Color(20,20,20,100), Color(255,255,255,255) )
			end
		end
	end
end 

hook.Add("HUDPaint", "Shan_LifeSupport_HUDPaint", lifesupport_HUDPaint)
-- shanjaq: End Life Support mod.
-- Start eHud Stuff
if not huddata then
	huddata = {}
end 

function lifesupport_think()
	local pl = LocalPlayer()
	
	if not pl:Alive() then
		return
	end
	
	huddata.lssAir = ls_air / 100
	huddata.lssAirRes = (huddata.lssAir - 1) / 19
	huddata.lssTmp = ls_tmp / 288
	huddata.lssShd = ls_shd / 2000
end
hook.Add("Think","lifesupport_think",lifesupport_think) 
-- End eHud Stuff


function LS_umsg_hook( um )
	ls_habitat = um:ReadShort()
	ls_air = um:ReadShort()
	ls_tmp = um:ReadShort()
	ls_shd = um:ReadShort()

end
usermessage.Hook("LS_umsg", LS_umsg_hook)  